﻿using SSC.Models;
using SSC.Services;
using SSC.ViewModels;
using System.Windows;

namespace SSC.Views
{
    /// <summary>
    /// wdFeed.xaml 的交互逻辑
    /// </summary>
    public partial class wdFeed : Window
    {
        public string SelectedPartName { get; private set; }
        public bool IsConfirmed { get; private set; }

        public wdFeed()
        {
            InitializeComponent();
            DataContext = new PartViewModel();
            LoadPartsFromDatabase(); // 加载料号列表
        }

        private void Send_Click(object sender, RoutedEventArgs e)
        {
            // 示例：你可以在这里读取控件值，比如 ComboBox/TextBox 等
            // SelectedPartName = cbPart.SelectedItem?.ToString(); // 假设你有个 ComboBox 名为 cbPart

            IsConfirmed = true;

            MessageBox.Show("参数已下发！");
            this.DialogResult = true;
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void LoadPartsFromDatabase()
        {
            try
            {
                List<PartModel> parts = PartService.GetPartModels(); // 使用你的服务类
                cbPart.ItemsSource = parts;
                cbPart.DisplayMemberPath = "PartName"; // 显示 PartName
                cbPart.SelectedIndex = parts.Count > 0 ? 0 : -1;
            }
            catch (Exception ex)
            {
                MessageBox.Show($"加载料号失败：{ex.Message}");
            }
        }
        private void cbPart_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
           
        }

    }
}
